'use strict';

const { Controller } = require('egg');

class userAnswerController extends Controller{
  async commit() {
    const { ctx } = this;
    const req = ctx.request.body;
    const res = await ctx.service.userAnswerService.commit(req.userAnswerList,req.e_id);
    ctx.body = ctx.helper.json(
        res.data ? res.data : null,
        res.suc ? 200 : 500,
        res.msg
    );
  }
  async get() {
    const { ctx } = this;
    const req = ctx.request.body;
    const res = await ctx.service.userAnswerService.get(req);
    ctx.body = ctx.helper.json(
        res.data ? res.data : null,
        res.suc ? 200 : 500,
        res.msg
    );
  }

  async getUserAllAnswer(){
    const { ctx } = this;
    const req = ctx.request.body;
    const res = await ctx.service.userAnswerService.getUserAllAnswer(req.u_id,req.e_id);
    ctx.body = ctx.helper.json(
        res.data ? res.data : null,
        res.suc ? 200 : 500,
        res.msg
    );
  }
  async getUserQuestionAnswer(){
    const { ctx } = this;
    const req = ctx.request.body;
    const res = await ctx.service.userAnswerService.getUserQuestionAnswer(req.u_id,req.e_id,req.q_id);
    ctx.body = ctx.helper.json(
        res.data ? res.data : null,
        res.suc ? 200 : 500,
        res.msg
    );
  }
  async userIsRight(){
    const { ctx } = this;
    const req = ctx.request.body;
    const res = await ctx.service.userAnswerService.userIsRight(req.u_id,req.e_id,req.q_id);
    ctx.body = ctx.helper.json(
        res.data ? res.data : null,
        res.suc ? 200 : 500,
        res.msg
    );
  }
}

module.exports = userAnswerController